package cn.hlyc.mq.delay;


import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * 生产者
 */



public class delayProducer {
    public static void main(String[] args)throws Exception {
        //创建生产者实例
        DefaultMQProducer producer = new DefaultMQProducer("mq-delay-producer-group");
        //设置mq的nameserver地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        //启动生产者
        producer.start();

        byte[] msgByteArray = "延迟".getBytes(RemotingHelper.DEFAULT_CHARSET);

        Message message = new Message("delay-topic", "delay-tag", msgByteArray);

        //发送延迟消息    等级
        message.setDelayTimeLevel(2);

        //发消息
        SendResult sendResult = producer.send(message);
        System.out.println(sendResult);

        //关闭资源
        producer.shutdown();


    }
}
